package com.miaoquan.mqapitbk.controller;

import com.miaoquan.mqapitbk.service.SearchService;
import com.miaoquan.mqcommon.api.CommonPage;
import com.miaoquan.mqcommon.api.CommonResult;
import com.miaoquan.mqmbg.model.TbkProduct;
import com.taobao.api.ApiException;
import com.taobao.api.request.TbkDgMaterialOptionalRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 搜索Controller
 *
 * @author Fa
 * @date 2020-04-03 16:32
 */
@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 商品搜索
     */
    @GetMapping("/product")
    public CommonResult<CommonPage<TbkProduct>> searchProduct(
            @RequestParam(required = false, defaultValue = "1") Long pageNum,
            @RequestParam(required = false) boolean isTmall,
            @RequestParam String q
    ) throws ApiException {
        return searchService.searchProduct(pageNum, isTmall, q);
    }

    /**
     * 商品搜索-all
     */
    @PostMapping("/product/all")
    public CommonResult<CommonPage<TbkProduct>> searchProduct(
            @RequestBody TbkDgMaterialOptionalRequest tbkDgMaterialOptionalRequest) throws ApiException {
        return searchService.searchProduct(tbkDgMaterialOptionalRequest);
    }

}
